<%--
 * (c)2010-2011 Andrea Caltroni (andrea.caltroni@pd.infn.it), INFN (www.infn.it)
 *
 * This file is part of the IGI Survey Portlet (from here on shortened to IGISP).
 * IGISP is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) any 
 * later version.
 *
 * IGISP is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IGISP. If not, see <http://www.gnu.org/licenses/>.
 *
--%>

<%@ include file="./init.jsp" %>

<% pageContext.setAttribute("newLineChar", "\n"); %>
<% pageContext.setAttribute("newLineHtml", "<br />"); %>

<c:set var="numQuestions" value="${fn:length(survey.questions)}" />

<h3><spring:message code="surveyQuestions.view.title"/></h3>
<table class="lfr-table">
    <tr>
        <th><spring:message code="survey.label.survey"/>:</th>
        <td><a href="<portlet:renderURL><portlet:param name="action" value="viewSurvey"/><portlet:param name="surveyID" value="${survey.id}"/></portlet:renderURL>">${survey.name}</a></td>
    </tr>
</table>
<div class="lfr-separator">&nbsp;</div>

<div class="portlet-body">

    <table class="lfr-table">
<c:choose><c:when test="${numQuestions <= 0}">
        <tr>
            <td colspan="3"><spring:message code="survey.label.noQuestions"/></td>
        </tr>
</c:when>
<c:otherwise>
        <tr>
            <th><spring:message code="question.label.position"/></th>
            <th><spring:message code="question.label.description"/></th>
            <th><spring:message code="question.label.answersType"/></th>
            <th>&nbsp;</th>
        </tr>
    <c:forEach var="question" items="${survey.questions}">
        <tr>
            <td>${question.position}</td>
            <td><c:out value="${fn:replace(question.description, newLineChar, newLineHtml)}" escapeXml="false" /></td>
            <td>${question.answersType.translatedName}</td>
            <c:set var="numAnswers" value="${fn:length(question.answers)}" />
            <td>
                <a href="<portlet:renderURL><portlet:param name="action" value="showEditQuestionForm"/><portlet:param name="surveyID" value="${survey.id}"/><portlet:param name="questionID" value="${question.id}"/></portlet:renderURL>"><img title="<spring:message code="question.edit.button"/>" src="<html:imagesPath/>edit.png" border=0 /></a>&nbsp;
                <a href="<portlet:actionURL>
                            <portlet:param name="action" value="deleteQuestion"/>
                            <portlet:param name="questionID" value="${question.id}"/>
                         </portlet:actionURL>
                         " onclick="return confirm('<spring:message code="message.confirm.delete.question"/>')">
                         <img title="<spring:message code="question.delete.button"/>" src="<html:imagesPath/>delete.png" border=0 /></a>
            <c:choose><c:when test="${numAnswers > 0}">
                <a href="<portlet:renderURL><portlet:param name="action" value="viewQuestionAnswers"/><portlet:param name="questionID" value="${question.id}"/></portlet:renderURL>"><spring:message code="survey.label.answers"/> [${numAnswers}]</a>&nbsp;
            </c:when>
            <c:otherwise>
                <a href="<portlet:renderURL><portlet:param name="action" value="showAddAnswerForm"/><portlet:param name="questionID" value="${question.id}"/></portlet:renderURL>"><img title="<spring:message code="answer.add.button"/>" src="<html:imagesPath/>new.png" border=0 /></a>
            </c:otherwise></c:choose>
            </td>
        </tr>
    </c:forEach>
</c:otherwise></c:choose>
    </table>

</div>

<div class="lfr-separator">&nbsp;</div>

<div class="lfr-toolbar">
    <a href="<portlet:renderURL><portlet:param name="action" value="showAddQuestionForm"/><portlet:param name="surveyID" value="${survey.id}"/></portlet:renderURL>"><img title="<spring:message code="question.add.button"/>" src="<html:imagesPath/>new.png" border=0 /></a>&nbsp;
    <a href="<portlet:renderURL><portlet:param name="action" value="showChangeQuestionOrderForm"/><portlet:param name="surveyID" value="${survey.id}"/></portlet:renderURL>"><img title="<spring:message code="surveyQuestions.changeOrder.button"/>" src="<html:imagesPath/>change-order.png" border=0 /></a>&nbsp;
	<a href="<portlet:renderURL portletMode="view"/>"><img title="<spring:message code="button.home"/>" src="<html:imagesPath/>home.png" border=0 /></a>
</div>
